package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.FeeRecordVo;
import org.dromara.nursing.domain.bo.FeeRecordBo;
import org.dromara.nursing.service.IFeeRecordService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 费用记录
 *
 * @author Xue
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/feeRecord")
public class FeeRecordController extends BaseController {

    private final IFeeRecordService feeRecordService;

    /**
     * 查询费用记录列表
     */
    // @SaCheckPermission("nursing:feeRecord:list") // 已移除权限验证
    @GetMapping("/list")
    public TableDataInfo<FeeRecordVo> list(FeeRecordBo bo, PageQuery pageQuery) {
        return feeRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出费用记录列表
     */
    // @SaCheckPermission("nursing:feeRecord:export") // 已移除权限验证
    @Log(title = "费用记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(FeeRecordBo bo, HttpServletResponse response) {
        List<FeeRecordVo> list = feeRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "费用记录", FeeRecordVo.class, response);
    }

    /**
     * 获取费用记录详细信息
     *
     * @param recordId 主键
     */
    // @SaCheckPermission("nursing:feeRecord:query") // 已移除权限验证
    @GetMapping("/{recordId}")
    public R<FeeRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long recordId) {
        return R.ok(feeRecordService.queryById(recordId));
    }

    /**
     * 新增费用记录
     */
    // @SaCheckPermission("nursing:feeRecord:add") // 已移除权限验证
    @Log(title = "费用记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody FeeRecordBo bo) {
        return toAjax(feeRecordService.insertByBo(bo));
    }

    /**
     * 修改费用记录
     */
    // @SaCheckPermission("nursing:feeRecord:edit") // 已移除权限验证
    @Log(title = "费用记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody FeeRecordBo bo) {
        return toAjax(feeRecordService.updateByBo(bo));
    }

    /**
     * 删除费用记录
     *
     * @param recordIds 主键串
     */
    // @SaCheckPermission("nursing:feeRecord:remove") // 已移除权限验证
    @Log(title = "费用记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{recordIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] recordIds) {
        return toAjax(feeRecordService.deleteWithValidByIds(List.of(recordIds), true));
    }
}
